from z_common import *
import pandas as pd

class CSVProc:
    '''
    转换成标准的 csv
    '''
    def __init__(self):
        super().__init__()
        self.__name__ = 'CSVProc.__call__'
    
    def __call__(self, in_file_path, out_file_path):
        dfi = pd.read_csv(in_file_path, index_col=0, encoding='gbk')
        dfi = dfi.loc[ : , ~dfi.columns.str.contains("^Unnamed")]
        # print(dfi)
        dfi2 = pd.DataFrame(dfi.values.T, index=dfi.columns, columns=dfi.index)
        for column in dfi2.columns:
            dfi2[column] = pd.to_numeric(dfi2[column], errors='coerce')
        # dfi2.apply(pd.to_numeric, errors='coerce')
        dfi2.reset_index(inplace=True)
        dfi2.rename(columns={'index':'报告日期'}, inplace=True)
        # print(dfi2)
        
        dfi2.to_csv(out_file_path, index=False, encoding='gbk')

if __name__ == '__main__' : 
    csv_proc = CSVProc()
    # csv_proc(r'analyse_data\a\000001.txt', r'analyse_data\a\000001.csv')
    file_process(r'analyse_data\a', '.txt', r'analyse_data\a', '.csv', csv_proc, skip_exists=False)
    ring()